define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'books/book/index' + location.search,
                    add_url: 'books/book/add',
                    edit_url: 'books/book/edit',
                    del_url: 'books/book/del',
                    multi_url: 'books/book/multi',
                    table: 'book',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'),operate:'LIKE'},
                        {field: 'cover', title: __('Cover'),
                            events: Table.api.events.image,
                            formatter: Table.api.formatter.image,operate:false},
                        // {field: 'descr', title: __('Descr')},
                        // {field: 'm_id', title: __('M_id')},
                        {field: 'author', title: __('Author'),operate:'LIKE'},

                        {field: 'cate_name', title: __('Cate_name'),operate:false},
                        // {field: 'cate_id', title: __('Cate_id')},
                        // {field: 'cate_pid', title: __('Cate_pid')},

                        {field: 'words', title: __('Words'),operate:false},
                        {field: 'tuijian', title: __('Tuijian'),operate:false},
                        {field: 'dasang', title: __('Dasang'),operate:false},

                        {field: 'recommendation', title: __('Recommendation'),
                            searchList: {"0":"下架","1":"上架"},
                            custom: {"0":"","1":"success"},
                            iconList: false,
                            width:'5%',
                            formatter: Table.api.formatter.status,searchable: false},
                        {field: 'original', title: __('Original'),
                            searchList: {"0":"下架","1":"上架"},
                            custom: {"0":"","1":"success"},
                            iconList: false,
                            width:'5%',
                            formatter: Table.api.formatter.status,searchable: false,operate:false},
                        {field: 'original_new', title: __('Original_new'),
                            searchList: {"0":"下架","1":"上架"},
                            custom: {"0":"","1":"success"},
                            iconList: false,
                            width:'5%',
                            formatter: Table.api.formatter.status,searchable: false},
                        {field: 'new', title: __('New'),
                            searchList: {"0":"下架","1":"上架"},
                            custom: {"0":"","1":"success"},
                            iconList: false,
                            width:'5%',
                            formatter: Table.api.formatter.status,searchable: false},
                        {field: 'recently', title: __('Recently'),
                            searchList: {"0":"下架","1":"上架"},
                            custom: {"0":"","1":"success"},
                            iconList: false,
                            width:'5%',
                            formatter: Table.api.formatter.status,searchable: false},


                        {field: 'complete', title: __('Complete'),
                            searchList: {"0":"未完本","1":"完本"},
                            custom: {"0":"","1":"success"},
                            iconList: false,
                            width:'5%',
                            formatter: Table.api.formatter.status,searchable: false},
                        {field: 'more_list', title: __('More_list'),
                            searchList: {"0":"下架","1":"上架"},
                            custom: {"0":"","1":"success"},
                            iconList: false,
                            width:'5%',
                            formatter: Table.api.formatter.status,searchable: false},
                        {field: 'new_book_list', title: __('New_book_list'),
                            searchList: {"0":"下架","1":"上架"},
                            custom: {"0":"","1":"success"},
                            iconList: false,
                            width:'5%',
                            formatter: Table.api.formatter.status,searchable: false},
                        {field: 'ticket_list', title: __('Ticket_list'),
                            searchList: {"0":"下架","1":"上架"},
                            custom: {"0":"","1":"success"},
                            iconList: false,
                            width:'5%',
                            formatter: Table.api.formatter.status,searchable: false},
                        {field: 'auto_free', title: __('Auto_free'),
                            searchList: {"0":"否","1":"是"},
                            custom: {"0":"","1":"success"},
                            iconList: false,
                            width:'5%',
                            formatter: Table.api.formatter.status,searchable: false},
                        {field: 'update', title: __('Update'), operate:'RANGE', addclass:'datetimerange',operate:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});